/**
 * Created by webrx on 2024/4/26.
 */
import {createWebHashHistory, createRouter} from 'vue-router'
import type {RouteRecordRaw} from 'vue-router'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

NProgress.configure({
    minimum: 0.1, // 进度条最小百分比
    template: `
    <div class="bar" role="bar">
      <div class="peg"></div>
    </div>
    <div class="spinner" role="spinner">
      <div class="spinner-icon"></div>
    </div>
  `, // 自定义进度条样式
});

const routes: RouteRecordRaw[] = [
    {
        path: '/home',
        component: () => import('@/views/home.vue'),
    }, {
        path: '/st',
        name: 'st',
        component: () => import('@/views/student.vue'),
    }, {
        path: '/',
        redirect: '/home'
    }
]

const router = createRouter({
    history: createWebHashHistory(),
    routes
})

router.beforeEach((to, from, next) => {
    NProgress.start()
    if (to.meta.title) {
        document.title = to.meta.title.toString()
    } else {
        document.title = ''
    }
    next()
})

router.afterEach(() => {
    NProgress.done(); // 结束进度条
});

export default router
